<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./js/axios.min.js"></script>
  </head>
  <body>
    <input type="text" name="" id="" />
    <input type="password" name="" id="" />
    <input type="button" name="" id="" value="注册" />
    <script>
      //1-给注册按钮加事件
      let ipts = document.querySelectorAll("input");
      ipts[2].onclick = function () {
        let uname = ipts[0].value;
        let pd = ipts[1].value;

        //2-请求
        let regAPI = "http://jx.xuzhixiang.top/ap/api/reg.php";
        axios
          .get(regAPI, { params: { username: uname, password: pd } })
          .then((r) => {
            console.log(r.data);
            alert(r.data.msg);
            if (r.data.code == 1) {
              location.href = "login.html";
            }
          });
      };
    </script>
  </body>
</html>
